package com.realgodo.site.web;

import java.io.ByteArrayInputStream;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springside.modules.web.struts2.Struts2Utils;

import com.opensymphony.xwork2.ActionSupport;
import com.realgodo.site.utils.RandomCodeUtil;

/**随即吗*/
@Results( 
		{ @Result(name = "code", type = "stream", params = { "contentType",
				"image/jpeg", "inputName", "inputStream",
				"contentDisposition", "attachment;filename=\"${fileName}\"" })
		})
public class RandomController extends ActionSupport{

	/***/
	private static final long serialVersionUID = -8335006867725322388L;
	
	private ByteArrayInputStream inputStream;
	private String code;
	private boolean iscorrect;
	private String fileName;
	@Override
	public String execute() throws Exception {
		this.setInputStream(RandomCodeUtil.getRandomCode(Struts2Utils.getSession()));
		return "code";
	}
	
	public String checkCode(){
		Struts2Utils.renderText(Boolean.valueOf(this.code.equals(Struts2Utils.getSession().getAttribute("rand"))).toString());
		return null;
	}
	
	public ByteArrayInputStream getInputStream(){
		return inputStream;
	}
	public void setInputStream(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public boolean isIscorrect() {
		return iscorrect;
	}

	public void setIscorrect(boolean iscorrect) {
		this.iscorrect = iscorrect;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

}
